var notifyUtil = function () {

    // var notices = {},//对象形式，key是notifyPushId，value是通知对象
    //     timer,
    //     urlAudioMap = {},
    //     noticePushIdOptMap = {},
    //     readNoticePushIdQueue = new Queue(),
    //     linkTypeOptionMap = {},
    //     originTitle = document.title;

    /**
     * 操作
     * @type {{icon: string, title: string, message: string, url: string, target: string}}
     */
    var content = {
        // options
        icon: 'https://randomuser.me/api/portraits/med/men/77.jpg',
        title: '',
        message: '',
        url: '',
        target: '_blank'
    };

    /**
     * 弹层模板
     * @type {string}
     */
    var template =  '<div data-notify="container" class="col-xs-11 col-sm-3 alert alert-{0}" role="alert">' +
                    '<button type="button" aria-hidden="true" class="close" data-notify="dismiss">×</button>' +
                    '<img data-notify="icon" class="img-circle pull-left">' +
                    '<span data-notify="title">{1}</span>' +
                    '<span data-notify="message">{2}</span>' +
                    '<a href="{3}" target="{4}" data-notify="url"></a>' +
                    '</div>'

    /**
     * 弹层设置
     * @type {{showProgressbar: boolean, template, mouse_over: null, onClosed: null, z_index: number, onShow: null, offset: number, newest_on_top: boolean, type: string, animate: {exit: string, enter: string}, timer: number, onClose: null, spacing: number, delay: number, url_target: string, allow_dismiss: boolean, onShown: null, position: null, placement: {from: string, align: string}, element: string, icon_type: string}}
     */
    var settings = {
        // settings
        placement: {
            from: "bottom",
            align: "right"
        },
        element: 'body',
        position: null,
        allow_dismiss: true,
        showProgressbar: false,
        placement: {
            from: "bottom",
            align: "right"
        },
        newest_on_top: false,//在底部挨个显示
        offset: 20,
        spacing: 10,
        z_index: 1031,
        delay: 5000,
        timer: 1000,
        url_target: '_blank',
        mouse_over: null,
        animate: {
            enter: 'animated fadeInRight',
            exit: 'animated fadeOutRight'
        },
        onShow: null,
        onShown: null,
        onClose: null,
        onClosed: null,
        icon_type: 'class',
        type: 'minimalist',
        icon_type: 'image',
        template: template
    }

    var notify;

    /**
     * 开启通知
     * @param option
     */
    function notifyNotice(option,setting) {
        notify = $.notify($.extend(true,content,option),$.extend(true,settings,setting));
    }

    /**
     * 关闭所有通知
     */
    function notifyCloseAll(){
        $.notifyClose();
    }

    /**
     * 同一个linkType类型的通知，只显示一个
     * @param notice
     * @param option
     */
    function singleNotifyByLinkType(notice, option) {

        if (notice.linkType) {
            if (window != window.top) {
                window.top.NotifyUtil.singleNotifyByLinkType(notice, option)
            } else {
                var findMore = false;
                for (var i = 0; i < notices.length; i++) {
                    var n = notices[i];
                    if (n.linkType && n.linkType.code === notice.linkType.code) {
                        findMore = true
                        break
                    }
                }
                if (!findMore) {
                    notifyNotice(notice, option)
                }
            }
        }
    }

    /**
     * 播放声音
     * @returns {player}
     */
    function playAudio(url) {
        var audio = urlAudioMap[url]
        if (!audio) {
            audio = createAudio(url)
            document.body.appendChild(audio)
            urlAudioMap[url] = audio
        }
        audio.play()
        return audio
    }

    /**
     * 创建音频dom
     * @param url
     * @returns {HTMLAudioElement}
     */
    function createAudio(url) {
        var audioElm = document.createElement('audio'),
            source;
        if ($.isArray(url) && url.length > 0) {
            for (var i = 0; i < url.length; i++) {
                source = document.createElement('source');
                source.src = url[i];
                source.type = 'audio/' + getExtension(url[i]);
                audioElm.appendChild(source);
            }
        } else {
            audioElm.src = url;
        }
        return audioElm;
    }

    /**
     * 获取文件后缀
     * @param file_name
     * @returns {*}
     */
    function getExtension(file_name) {
        return file_name.match(/\.([^\.]+)$/)[1];
    }

    /**
     * 事件更新
     */
    function update() {
        notify.update('title', '...');
        notify.update('message', '...');
        notify.update('icon', '...');
        notify.update('type', '...');
        notify.update('progress', '...');
        notify.update('url', '...');
        notify.update('target', '...');
    }

    return{
        notifyNotice:notifyNotice,
        notifyCloseAll:notifyCloseAll
    }
}();